<?php
/**
 * Author: qiba@ibantang.com, 2019, all rights reserved.
 * Date: 2019-04-22
 * Time: 15:24
 */

namespace Core\Common\Base;

class RoundRobin
{
    const TYPE_INT = \Swoole\Table::TYPE_INT;
    const TYPE_STRING = \Swoole\Table::TYPE_STRING;
    private static $instance;

    public static function initRoundRobinTable($size = 65535)
    {
        $table = new \Swoole\Table($size);
//        $table->column('service', self::TYPE_STRING, 300);
        $table->column('index', self::TYPE_INT, 8);
        $table->create();
        self::$instance = $table;
    }

    public static function setService($service)
    {
        // 已经不再需要
    }

    public static function getInstance()
    {
        return self::$instance;
    }

    public static function incr($serviceId)
    {
        return self::$instance->incr($serviceId, 'index', 1);
    }
}
